package com.projectx.action.findPassword;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextPaint;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.textfield.TextInputLayout;
import com.google.gson.Gson;
import com.projectx.R;
import com.projectx.action.MainActivity;
import com.projectx.action.login.LoginActivity2;
import com.projectx.entity.User;
import com.projectx.util.ActivityManage;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
/**
 * 因为后端的垃圾接口现在功能已经废弃
 */
public class ChangePassword extends AppCompatActivity {
    private ProgressBar progressBar;
    private String accountName;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityManage.addActivity("ChangePassword",this);
        setContentView(R.layout.forget_change_password);

        final EditText passwordInput = findViewById(R.id.PasswordEditText);
        final TextInputLayout passwordInputLayout = findViewById(R.id.PasswordEditField);
        final EditText passwordInput2 = findViewById(R.id.PasswordEditText2);
        final TextInputLayout passwordInputLayout2 = findViewById(R.id.PasswordEditField2);
        final Intent accountIntent = getIntent();
        accountName = accountIntent.getStringExtra("accountName");
        final TextView textView = findViewById(R.id.ChangePasswordText);
        final TextView accountText = findViewById(R.id.AccountText);
        final Button finish = findViewById(R.id.ChangeFinish);
        progressBar = findViewById(R.id.FindProgress);
        progressBar.setVisibility(View.INVISIBLE);

        accountText.setText(accountName);
        TextPaint textPaint = textView.getPaint();
        textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        textPaint.setStrokeWidth(2);

        finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String password1 = passwordInput.getText().toString();
                String password2 = passwordInput2.getText().toString();
                if (password1.isEmpty()) {
                    passwordInputLayout.setError("密码不能为空");
                } else if (password2.isEmpty()) {
                    passwordInputLayout.setErrorEnabled(false);
                    passwordInputLayout2.setError("密码不能为空");
                } else {
                    passwordInputLayout.setErrorEnabled(false);
                    passwordInputLayout2.setErrorEnabled(false);
                    progressBar.setVisibility(View.VISIBLE);
                    //处理数据
                    Intent intent = new Intent(ChangePassword.this, LoginActivity2.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                    startActivity(intent);
                    ActivityManage.exitActivity("ChangePassword");
                    ActivityManage.exitActivity("FindAccount");
                    ActivityManage.exitActivity("FindPassword");
                }
            }
        });

    }
}
